package com.swq.java.code.chapter17.code04;

import com.swq.java.code.chapter17.code03.Person;

import java.util.*;

public class EachTester {
    public static void main(String[] args) {

        List<Person> persons = new ArrayList<Person>() {
            {  //匿名类初始化代码
                add(new Person("Tom", 21));
                add(new Person("Mike", 32));
                add(new Person("Linda", 19));
            }
        };

        persons.forEach((Person p) -> {  //Lambda表达式,相当于是Consumer类型的匿名对象
                    //指定对每个元素的具体操作
                    p.setAge(p.getAge() + 1);
                    System.out.println(p.getName() + ":" + p.getAge());
                }
        );

        persons.forEach(p -> {
            p.setAge(p.getAge() + 1);
            System.out.println(p.getName() + ":" + p.getAge());
        });

    }
}